package itman.controller;

import itman.po.DeliveryAddress;
import itman.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/DeliveryAddressController")
public class DeliveryAddressController {
    @Autowired
    private DeliveryAddressService deliveryAddressService;

    /**
     * 根据用户编号查询所属送货地址
     * @param deliveryAddress
     * @return
     */
    @RequestMapping("/listDeliveryAddressByUserId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(DeliveryAddress deliveryAddress) {
        return deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId());
    }

    /**
     * 根据送货地址编号查询送货地址
     * @param deliveryAddress
     * @return
     */
    @RequestMapping("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(DeliveryAddress deliveryAddress) {
        return deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
    }

    /**
     * 向送货地址表中添加一条记录
     * @param deliveryaddress
     * @return
     */
    @RequestMapping("/saveDeliveryAddress")
    public int saveDeliveryAddress(DeliveryAddress deliveryaddress) {
        return deliveryAddressService.saveDeliveryAddress(deliveryaddress);
    }

    /**
     * 根据送货地址编号更新送货地址信息
     * @param deliveryaddress
     * @return
     */
    @RequestMapping("/updateDeliveryAddress")
    public int updateDeliveryAddress(DeliveryAddress deliveryaddress) {
        return deliveryAddressService.updateDeliveryAddress(deliveryaddress);
    }

    /**
     * 根据送货地址编号删除一条记录
     * @param daId
     * @return
     */
    @RequestMapping("/removeDeliveryAddress")
    public int removeDeliveryAddress(Integer daId) {
        return deliveryAddressService.removeDeliveryAddress(daId);
    }
}
